package client.gui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;

import client.DutyFree;
import client.DutyFreeClient;
import client.Service;

public class DutyFreePanel extends DisplayPanel implements MouseListener, ActionListener {
	private static final long serialVersionUID = -8844414678998615696L;
	private final JButton dutyFreeList = new JButton("Get Duty Free List");
	private final JPanel displayPanel = new JPanel();
	private JScrollPane scroll;
	private ArrayList<ItemPanel> items;
	
	public DutyFreePanel(Service s) {
		super(s);
		items = new ArrayList<ItemPanel>();
		init();
	}
	private void init(){
		add(dutyFreeList);
		dutyFreeList.addActionListener(this);
		displayPanel.setPreferredSize(new Dimension(750, 5000));
		scroll = new JScrollPane(displayPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scroll.getVerticalScrollBar().setUnitIncrement(50);
		scroll.setPreferredSize(new Dimension(750,500));
		add(scroll);
	}
	
	public void actionPerformed(ActionEvent arg0) {
		displayPanel.removeAll();
		items.clear();
		System.out.println("Updated stuff");
		if(arg0.getSource() == dutyFreeList){
			ArrayList<DutyFree> s = ((DutyFreeClient) myClient).getDFList();
			removeAllItems();
			for (DutyFree d : s) {
				DutyFreeInfoPanel dp = new DutyFreeInfoPanel(d);
				addItem(dp);
			}
			updateUI();
		}		
	}
	public void removeAllItems(){
		displayPanel.removeAll();
		items.clear();
	}

	public void addItem(ItemPanel i){
		items.add(i);
		displayPanel.add(i);
		i.setML(this);
	}
	
	public void mouseClicked(MouseEvent arg0) {}
	public void mouseEntered(MouseEvent arg0) {}
	public void mouseExited(MouseEvent arg0) {}
	public void mousePressed(MouseEvent arg0) {}
	public void mouseReleased(MouseEvent arg0) {}
}
